<template>
  <list-condition-template
    ref="table"
    :rows="rows"
    :defaultSort="{ prop: 'createTime', order: 'descending' }"
    :total="total"
    @page-info-change="handlePageInfoChange"
    :search-data="listQuery"
    :batch-column="false"
  >
    <template slot="condition">

     <el-form-item prop="keyword">
        <el-input
          placeholder="名称 | 电话 | 地址"
          v-model="listQuery.keyword"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item prop="enable">
        <el-select
          v-model="listQuery.enable"
          value-key="name"
          clearable
          placeholder="是否启用"
        >
          <el-option
            v-for="(item, key) in $CONST.ACTIVE_STATUS"
            :key="key"
            :label="item.title"
            :value="item"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item prop="photoStudioId">
        <el-select
          v-model="listQuery.levelId"
          placeholder="等级"
          filterable
          clearable
          :loading="selectLoading"
          @focus="getLevelSelect"
        >
          <el-option
            v-for="item in levels"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>

    </template>

    <template slot="columns">
      <el-table-column
        label="名字"
        min-width="160"
        align="center"
        property="name"
        fixed
      ></el-table-column>
      <el-table-column
        label="电话"
        align="center"
        property="tel"
      ></el-table-column>
      <el-table-column
        label="地址"
        align="center"
        min-width="200"
        property="address"
      ></el-table-column>
      <el-table-column
        label="等级"
        align="center"
        property="level.name"
      ></el-table-column>
      <el-table-column
        label="余额"
        min-width="100"
        align="center"
        property="amount"
      ></el-table-column>
      <el-table-column
        label="是否启用"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag :type="scope.row.enable?'success':'danger'">{{
            scope.row.enable ?'启用':'禁用'
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="创建日期"
        sortable="custom"
        min-width="150"
        align="center"
        property="createTime"
      ></el-table-column>
      <el-table-column
        label="等级过期时间"
        sortable="custom"
        min-width="150"
        align="center"
      >
       <template slot-scope="scope">
          <span>{{scope.row.levelEndTime || '永不过期'}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        align="center"
        label="详情"
        class-name="fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="showDetail(scope.row)"
            v-waves
          >查看</el-button>
        </template>
      </el-table-column> -->
    </template>
  </list-condition-template>
</template>

<script>
import levelAPI from '@/api/level'
import studioAPI from '@/api/photoStudio'
import waves from '@/directive/waves' // 水波纹指令
import ListConditionTemplate from '@/components/templates/listConditionTemplate'

export default {
  directives: {
    waves
  },
  components: {
    ListConditionTemplate
  },
  data () {
    return {
      selectLoading: false,
      rows: [],
      total: 0,
      dateArray: [],
      listQuery: {},
      levels: []
    }
  },
  methods: {
    /**
     * 查询影楼下拉框信息
     */
    getLevelSelect (keyword) {
      if (this.listQuery.levelId) {
        return
      }
      this.selectLoading = true
      levelAPI
        .getAll({ showLoading: false })
        .then((res) => {
          this.levels = res.data
          this.selectLoading = false
        })
        .catch((e) => {
          this.selectLoading = false
        })
    },
    /**
     * 加载数据
     */
    getList (pageInfo) {
      studioAPI
        .getPaged({ condition: this.listQuery, pageInfo })
        .then((response) => {
          console.log('res', response)

          this.rows = response.data.content
          this.total = response.data.totalElements
        })
    },
    /**
     * 搜索条件变更处理
     */
    handleFilter () {
      this.$refs.table.changeCondition()
    },
    /**
     * 分页信息变动事件处理
     * @param  {Object} pageInfo 分页信息
     */
    handlePageInfoChange (pageInfo) {
      this.getList(pageInfo)
    },
    /**
     * 查看详情点击处理
     * @param {*} row 参数
     */
    showDetail (row) {
      this.$router.pushTo(this.$router.routesConfig.studioInfo, row.id)
    },
    /**
     * 新增
     */
    handleCreate () {
      this.$router.pushTo(this.$router.routesConfig.studioInfo)
    }
  }
}
</script>
